<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <style>
        .table-box {
            width: 800px;
            height: 800px;
            margin: 0 auto;
        }

        h2 {
            text-align: center;
        }

        td {
            text-align: center;
        }

        th {
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="table-box">
        <h2>用户列表</h2>
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>id</th>
                    <th>用户名</th>
                    <th>电话号码</th>
                    <th>电子邮箱</th>
                    <th>注册时间</th>
                </tr>
            </thead>
            <tbody id="myTable">
                <tr>
                    
                </tr>
            </tbody>
        </table>
    </div>

    <script src="../js/jquery.min.js"></script>
    <script>
        function initTable(userArr) {

            let myTable = document.getElementById('myTable')

            let data = ''

            for (let i = 0; i < userArr.length; i++) {
                let str =
                    '<tr>' +
                    '<td>' + userArr[i].id + '</td>' +
                    '<td>' + userArr[i].userName + '</td>' +
                    '<td>' + userArr[i].phone + '</td>' +
                    '<td>' + userArr[i].email + '</td>' +
                    '<td>' + userArr[i].createTime + '</td>' +
                    '</tr>'
                data += str
            }

            myTable.innerHTML = data
        }

        $.ajax({
            type: 'get',
            url: 'http://www.cloud-ygo.com.cn:33599/api/web-api/user/list',
            dataType: 'json',
            success: function(res) {
                let respData = res.body
                initTable(respData)
            },
        })

    </script>
</body>

</html>